cmake_minimum_required(VERSION 3.10)

# 
project(mpc_solver VERSION 1.0 LANGUAGES CXX)

# 
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_C_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")

# specific your options 
option(RECORD_DATA "record data" OFF)

# openMP settings
FIND_PACKAGE(OpenMP REQUIRED)
if (OPENMP_FOUND)
    message("OPENMP FOUND")
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif ()

# Eigen
find_package(Eigen3 REQUIRED)
include_directories(${EIGEN3_INCLUDE_DIRS})

# OPENBLAS
find_package(OpenBLAS REQUIRED)
include_directories(${OpenBLAS_INCLUDE_DIRS})

# homo_ocp
find_library(HOMO_OCP_LIBRARY homo_ocp)

# ====================可执行文件====================
include_directories(
    ./prob
    ../communicate
    ../dependency/cpp_tools
)

# 
file(GLOB PROB_SOURCES 
    ./prob/*.cpp
)

add_library(prob
    ${PROB_SOURCES}
)

target_compile_options(prob PRIVATE $<$<CONFIG:Release>:-O3>)

if (RECORD_DATA)
    message("=====record data=====")
    add_definitions(-DRECORD)
else (RECORD_DATA)
	message("=====no record=====")
endif (RECORD_DATA)


# 
file(GLOB SOLVER_SOURCES 
    *.cpp
)

add_executable(mpc_solver
    ${SOLVER_SOURCES}
)

target_link_libraries(mpc_solver 
    prob
    homo_ocp
    tinyxml2
    serialib
    ${OpenBLAS_LIBRARIES} 
)
